package com.sqlcheck.common;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
@Schema(description = "通用响应结果")
public class Result<T> {
    
    @Schema(description = "操作是否成功", example = "true")
    private boolean success;
    
    @Schema(description = "响应消息", example = "操作成功")
    private String message;
    
    @Schema(description = "响应数据")
    private T data;
    
    @Schema(description = "响应代码", example = "200")
    private String code;
    
    private Result() {}
    
    private Result(boolean success, String message, T data, String code) {
        this.success = success;
        this.message = message;
        this.data = data;
        this.code = code;
    }
    
    public static <T> Result<T> success() {
        return new Result<>(true, "操作成功", null, "200");
    }
    
    public static <T> Result<T> success(T data) {
        return new Result<>(true, "操作成功", data, "200");
    }
    
    public static <T> Result<T> success(T data, String message) {
        return new Result<>(true, message, data, "200");
    }
    
    public static <T> Result<T> error(String message) {
        return new Result<>(false, message, null, "500");
    }
    
    public static <T> Result<T> error(String message, String code) {
        return new Result<>(false, message, null, code);
    }
    
    public static <T> Result<T> error(String message, String code, T data) {
        return new Result<>(false, message, data, code);
    }
}